package org.toonan.rental.chart;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;

public class BarChartView extends View
{
	private static final int[] colors;
	private static final int[] drawableIds;
	private boolean animMode = true;
	private String category = "%";
	private boolean display = true;
	private float endHeight = this.startHeight;
	private Paint fontPaint;
	private Handler handler = new Handler()
	{
		public void handleMessage(Message paramMessage)
		{
			super.handleMessage(paramMessage);
			if ((paramMessage.what == 1) && (BarChartView.this.indexSize < BarChartView.this.maxSize)
					&& (BarChartView.this.endHeight >= 20.0F))
			{
				BarChartView localBarChartView1 = BarChartView.this;
				localBarChartView1.endHeight -= BarChartView.this.rate;
				BarChartView localBarChartView2 = BarChartView.this;
				localBarChartView2.indexSize = (1.0F + localBarChartView2.indexSize);
			}
			
			BarChartView.this.invalidate();
			BarChartView.this.display = false;
			
		}
	};
	private float indexSize = 0.0F;
	private Paint linePaint;
	private float maxSize = 0.0F;
	private int numWidth = 9;
	private float rate = 3.4F;
	private Paint recPaint;
	private float startHeight = 342.0F;
	private Thread thread = new Thread()
	{
		public void run()
		{
			while (true)
			{
				if ((Thread.currentThread().isInterrupted()) || (!BarChartView.this.display))
					return;
				Message localMessage = new Message();
				localMessage.what = 1;
				BarChartView.this.handler.sendMessage(localMessage);
				try
				{
					Thread.sleep(15L);
				}
				catch (InterruptedException localInterruptedException)
				{
					Log.i("close", "InterruptedException！线程关闭");
					interrupt();
				}
			}
		}
	};
	private int viewWidth = 50;
	private int whichColor;
	
	static
	{
		int[] arrayOfInt = new int[7];
		arrayOfInt[0] = Color.rgb(61, 92, 169);
		arrayOfInt[1] = Color.rgb(157, 159, 0);
		arrayOfInt[2] = Color.rgb(180, 65, 65);
		arrayOfInt[3] = Color.rgb(105, 82, 134);
		arrayOfInt[4] = Color.rgb(31, 138, 28);
		arrayOfInt[5] = Color.rgb(1, 134, 126);
		arrayOfInt[6] = Color.rgb(144, 79, 1);
		colors = arrayOfInt;
		drawableIds = new int[] { R.drawable.blue_bar, R.drawable.yellow_bar, R.drawable.pink_bar,
				R.drawable.purple_bar, R.drawable.green_bar, R.drawable.cyan_bar, R.drawable.cafe_bar };
	}
	
	public BarChartView(Context paramContext, float paramFloat, String paramString, int paramInt,
			boolean paramBoolean)
	{
		super(paramContext);
		this.maxSize = paramFloat;
		this.category = paramString;
		this.whichColor = paramInt;
		this.animMode = paramBoolean;
		init();
	}
	
	public BarChartView(Context paramContext, int paramInt, String paramString)
	{
		super(paramContext);
		this.maxSize = paramInt;
		this.category = paramString;
	}
	
	public BarChartView(Context paramContext, int paramInt1, String paramString, int paramInt2)
	{
		super(paramContext);
		this.maxSize = paramInt1;
		this.category = paramString;
		this.whichColor = paramInt2;
		init();
	}
	
	private void init()
	{
		this.recPaint = new Paint();
		this.fontPaint = new Paint();
		this.fontPaint.setAntiAlias(true);
		this.fontPaint.setTypeface(Typeface.defaultFromStyle(1));
		this.fontPaint.setColor(-16777216);
		this.fontPaint.setTextSize(25.0F);
		this.linePaint = new Paint();
		this.linePaint.setColor(-16777216);
		this.linePaint.setStrokeWidth(2.0F);
		this.numWidth = 2;
		if (this.maxSize < 10.0F)
			this.numWidth = 5;
		
		if (this.animMode)
			this.thread.start();
		
		if (this.maxSize >= 100.0F)
			this.numWidth = 8;
		
		this.display = false;
		this.indexSize = this.maxSize;
		this.endHeight = (this.startHeight - this.maxSize * this.rate);
		invalidate();
	}
	
	public int getColor(int paramInt)
	{
		return colors[paramInt];
	}
	
	protected void onDraw(Canvas paramCanvas)
	{
		super.onDraw(paramCanvas);
		paramCanvas.drawBitmap(
				((BitmapDrawable) getResources().getDrawable(drawableIds[this.whichColor])).getBitmap(),
				null,
				new Rect(5, (int) this.endHeight, (int) (5.0F + this.viewWidth), (int) this.startHeight),
				null);
		this.recPaint.setARGB(255, 99, 66, 0);
		paramCanvas.drawText(this.indexSize + "", this.numWidth, this.endHeight - 10.0F, this.fontPaint);
		this.recPaint.setARGB(255, 110, 210, 60);
		paramCanvas.drawText(this.category, 0.0F, 30.0F + this.startHeight, this.fontPaint);
	}
}
